#pragma once
#include <httplib.h>
#include <string>
#include <map>
#include <vector>
#include <memory>

// HttpResponse 结构体
struct HttpResponse
{
    int status = 0;
    httplib::Headers headers; // 直接用httplib::Headers
    std::string body;
    std::string error;
    bool ok = false;
};

class HttpClient
{
public:
    HttpClient(const std::string &host, int port = 443);

    void setDefaultHeaders(const httplib::Headers &headers);
    void setTimeout(int sec);
    void setFollowRedirect(bool on);
    // 新增：控制是否校验证书
    void enable_server_certificate_verification(bool enabled);
    HttpResponse get(const std::string &path,
                     const httplib::Headers &headers = {});
    HttpResponse post(const std::string &path,
                      const std::string &body,
                      const std::string &content_type = "application/json",
                      const httplib::Headers &headers = {});
    HttpResponse post(const std::string &path,
                      const httplib::Params &params,
                      const httplib::Headers &headers = {});
    HttpResponse put(const std::string &path,
                     const std::string &body,
                     const std::string &content_type = "application/json",
                     const httplib::Headers &headers = {});
    HttpResponse del(const std::string &path,
                     const httplib::Headers &headers = {});
    HttpResponse post(const std::string &path,
                      const httplib::MultipartFormDataItems &items,
                      const httplib::Headers &headers = {});

private:
    std::unique_ptr<httplib::SSLClient> cli_;
    httplib::Headers default_headers_;
};